var MouseUtil = {

	/* http://dunnbypaul.net/js_mouse/ */
	/* works on IE6,FF,Moz,Opera7 */
	getMouseXY : function ( event ) {
		var pos = { x:0, y:0, algor:'', id:'', target:'' };

		event = event ? event : window.event; /* for IE */

		if ( event ) { 
 
			if( MouseUtil._is_ff_moz_opera7_not_ie6_event( event ) ) {
				pos = MouseUtil._not_ie6_mouse_pos( event, pos );
			} else 
			if ( MouseUtil._is_ie6_ff_moz_opera7_event( event ) ) {
				pos = MouseUtil._ie6_etc_mouse_pos( event, pos );
			}
			pos.target = event.target || event.srcElement;
			if ( pos.target ) {
				pos.id = pos.target.getAttribute( 'id' );
			}
		}
		return pos;
	},

	up_scrolls : function( pos, max ) {
		var off = {x:0,y:0};
		if ( pos.target ) {
			var current = pos.target;
			var n = 0;
			while( current ) {
				if ( max && n++ > max ) {
					break;
				}
				if ( current.scrollLeft ) {
					off.x += current.scrollLeft;
				}
				if ( current.scrollTop ) {
					off.y += current.scrollTop;
				}
				current = current.parentNode;
			}
		}
		return off;
	},

	_is_ff_moz_opera7_not_ie6_event : function( event ) {
		return ( event.pageX || event.pageY );
	},

	_is_ie6_ff_moz_opera7_event : function( event ) {
		return ( event.clientX || event.clientY );
	},

	_not_ie6_mouse_pos : function( event, pos ) {
		pos.x = event.pageX;
		pos.y = event.pageY;
		pos.algor = '[e.pageX]';
		if (event.clientX || event.clientY) pos.algor += ' [e.clientX] '
		return pos;
	},

	_ie6_etc_mouse_pos : function( event, pos ) {
      	pos.x = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
      	pos.y = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
      	pos.algor = '[e.clientX]';
      	if (event.pageX || event.pageY) pos.algor += ' [e.pageX] '
		return pos
	},

	noop : function() {}
};
